package com.example.android_app;

import android.app.Application;



import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;

public class MainApplication extends Application {

    private final String engineId = "engine_id";
    public FlutterEngine flutterEngine;
    @Override
    public void onCreate() {
        super.onCreate();
    //   java.lang.AssertionError: DartEntrypoints can only be created once a FlutterEngine is created.
     //   DartExecutor.DartEntrypoint dartEntrypoint = DartExecutor.DartEntrypoint.createDefault();

        flutterEngine = new FlutterEngine(this,null, false);
        //自定义的flutter engine必须要提前设置路由
        flutterEngine.getNavigationChannel().setInitialRoute("/");
        //指定默认的dartEntryPoint, main函数
       // flutterEngine.getDartExecutor().executeDartEntrypoint(dartEntrypoint);
        FlutterInjector.instance().flutterLoader().startInitialization(this);
        String flutterAppPath = FlutterInjector.instance().flutterLoader().findAppBundlePath();
        DartExecutor.DartEntrypoint customEntryPoint = new DartExecutor.DartEntrypoint(flutterAppPath, "custommain");
        flutterEngine.getDartExecutor().executeDartEntrypoint(customEntryPoint);

        FlutterEngineCache.getInstance().put(engineId, flutterEngine);
    }
}
